﻿using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using Higgs.Web.AtomPub.Configurations;
using Higgs.Web.AtomPub.Models;

namespace Higgs.Web.AtomPub
{
    public static class AtomPublishingApp
    {
        private static readonly object LockObj = new object();
        private static string _productName;
        public static string ProductName
        {
            get
            {
                if(string.IsNullOrEmpty(_productName))
                {
                    lock(LockObj)
                    {
                        var product = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof (AssemblyProductAttribute), true)[0] as AssemblyProductAttribute;
                        _productName = product.Product;
                    }
                }
                return _productName; 
            }
        }

        public static IEntryRepository EntryRepository { get; set; }
        public static IMediaRepository MediaRepository { get; set; }

        public static void Start()
        {
            var routes = RouteTable.Routes;
            var setting = AtomPubConfigSection.Current;

            ControllerBuilder.Current.DefaultNamespaces.Add("Higgs.Web.AtomPub");
            AtomPublishingController.SetupRouteTable(routes, setting);
        }
    }
}
